<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@page import="sun.applet.resources.MsgAppletViewer_it"%>
<%@page import="utility.connections"%>
<%@page import="java.sql.*" %>
<%@include file="../../hom/chkUser.jsp"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>SELEZIONA BENE</title>
		<script type="text/javascript">
			function setCategoria()
			{
				cat = document.forms[0].cmbCat.value;
				location.href = "select_bene.jsp?cerca=0&order=1&cat="+cat;
			}
			
			function setSubCategoria()
			{
				cat = document.forms[0].cmbCat.value;
				subcat = document.forms[0].cmbSCat.value;
				location.href = "select_bene.jsp?cerca=0&order=1&cat="+cat+"&subcat="+subcat;
			}
			
			function setFornitore()
			{
				cat = document.forms[0].cmbCat.value;
				subcat = document.forms[0].cmbSCat.value;
				fornitore = document.forms[0].cmbFor.value;
				qry="select_bene.jsp?cerca=0&order=1&cat="+cat+"&subcat="+subcat+"&forn="+fornitore;
				location.href = qry;
			}
			
			function insert()
			{
				codice 			= document.forms[0].txtCodice.value;
				categoria 		= document.forms[0].txtCategoria.value;
				document.forms["frmFind"].submit;
			}
			function back()
			{
				location.href="../hadm.jsp";
			}
			function setOrder(index)
			{
				codice = 			document.forms[0].txtCodice.value;
				categoria = 		document.forms[0].cmbCat.value;
				sottocategoria = 	document.forms[0].cmbSCat.value;
				fornitore = 		document.forms[0].cmbFor.value;
				qry = "select_bene.jsp?cerca=1&order="+index+"&cat="+categoria+"&cod="+codice+"&subcat="+sottocategoria+"&forn="+fornitore;
				location.href = qry;
			}
		</script>
		<script type="text/javascript" src="../js/immagini.js" ></script>
	    <style type="text/css">
<!--
.style1 {color: #000000}
.style3 {color: #000000; font-weight: bold; }
-->
        </style>
</head>
	<link href="../../layout.css" rel="stylesheet" type="text/css" media="screen" />
	<body>
	<%!
		String cod;
		String cat;
		String subcat;
		String forn;
		String user;
		String cerca;
	 %>
		<form name="frmFind" method="post" action="../../insert_cat">
			          <%
	          		String codice = "" + request.getParameter("cod");
	          		String categoria = "" + request.getParameter("cat");
	          		 %>
		  <table width="100%" border="0" cellspacing="1" cellpadding="0">
	        <tr>
	          <td width="16%"><div align="right">SIGLA:</div></td>
	          <td width="84%"><input type="text" name="txtCodice" value = <%= codice %>
 />
	          </td>
	        </tr>
	        
	        <tr>
	          <td><div align="right">CATEGORIA:</div></td>
	          <td><input type="text" width="300" name="txtCategoria" value=<%=categoria%> />
	          </td>
	        </tr>
	        <tr>
	          <td><div align="right"></div></td>
	          <td><input type="submit" name="cmdCerca" value="AGGIUNGI" onClick="javascript:insert()"> 
	              
	              <input type="submit" name="cmdBack2" value="INDIETRO" onClick="this.form.action='../hadm.jsp'"></td>
	        </tr>
	      </table>
		</form>
		<p align="center">ELENCO CATEGORIE </p>
		<table width="100%" border="1" cellspacing="1" cellpadding="0" style="border:1px solid;">
          <tr>
            <td align="center" bgcolor="#FFFFFF" style="border:1px solid;" ><span class="style1"><strong class="style3">PROG</strong>.</span></td>
            <td align="center" bgcolor="#FFFFFF" style="border:1px solid;" ><span class="style1"><a href="javascript:setOrder(1)"><span class="style3"><strong>SIGLA</strong></span></span></td>
			<td align="center" bgcolor="#FFFFFF" style="border:1px solid;" ><span class="style1"><a href="javascript:setOrder(2)"><span class="style3">CATEGORIA</span>.</span></td>
		  </tr>
          <%
				
				Connection conn=connections.getConnection();
				Statement st=connections.getStatement();
				int order = Integer.parseInt(request.getParameter("order"));
				String qry = "SELECT * FROM CATEGORIABENE ORDER BY " + order;
				ResultSet rs = st.executeQuery(qry);
				int i=0;
					
				if(rs.isBeforeFirst()&&rs.isAfterLast())
				{
					//Avvisare che non ci sono record!!!!
				}
				else
				{
					while (rs.next())
					{
						String color;
	              		String bordercell;
	              		
	              		i++;
	              		
	              		if (i%2==0)
	              		{
	              			color ="\"#E0E0E0\"";
	              			bordercell="style=\"border:1px solid;\";";
	              		}
	              		else
	              		{
	              			color = "\"#EFFFEF\"";
	              			bordercell="style=\"border:1px solid;\";";
	              		}
	              		
	              		out.println("<tr>");
	              		out.println("<td align=\"right\""+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ "><span class=\"style1\">" + i + "</span></td>"); //prog.
	              		for(int col=1;col<3;col++)
	              		{
							String alignment="";
							alignment="left";
							out.println("<td align=\""+alignment+"\""+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ "><span class=\"style1\">" + rs.getString(col)+ "</span></td>");
	              		}
	              	}
	              		out.println("</tr>");
				}
			
			rs.close();
			st.close();
             %>
        </table>
		<p>&nbsp;</p>
	</body>
</html>